<!doctype html><html lang dir=ltr><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>10.1 ~ 10.7 | 汇编语言 | Hui.Ke - Blog</title><meta name=generator content="Hugo Eureka 0.9.3"><link rel=stylesheet href=https://b.hui.ke/css/eureka.min.9cec6350e37e534b0338fa9a085bf06855de3b0f2dcf857e792e5e97b07ea905d4d5513db554cbc26a9c3da622bae92d.css><script defer src=https://b.hui.ke/js/eureka.min.fa9a6bf6d7a50bb635b4cca7d2ba5cf3dfb095ae3798773f1328f7950028b48c17d06276594e1b5f244a25a6c969a705.js></script>
<link rel=preconnect href=https://fonts.googleapis.com><link rel=preconnect href=https://fonts.gstatic.com crossorigin><link rel=preload href="https://fonts.googleapis.com/css2?family=Lora:wght@400;600;700&family=Noto+Serif+SC:wght@400;600;700&display=swap" as=style onload='this.onload=null,this.rel="stylesheet"'><link rel=stylesheet href=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/styles/vs.min.css media=print onload='this.media="all",this.onload=null' crossorigin><script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/bash.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/ini.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/json.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/php.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/python.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/shell.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/sql.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/x86asm.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/xml.min.js crossorigin></script>
<link rel=stylesheet href=https://b.hui.ke/css/highlightjs.min.2958991528e43eb6fc9b8c4f2b8e052f79c4010718e1d1e888a777620e9ee63021c2c57ec7417a3108019bb8c41943e6.css media=print onload='this.media="all",this.onload=null'><script defer type=text/javascript src=https://lib.baomitu.com/font-awesome/6.1.1/js/all.min.js></script>
<link rel=stylesheet href=https://cdn.jsdelivr.net/npm/katex@0.15.2/dist/katex.min.css integrity=sha384-MlJdn/WNKDGXveldHDdyRP1R4CTHr3FeuDNfhsLPYrq2t0UBkUdK2jyTnXPEK1NQ media=print onload='this.media="all",this.onload=null' crossorigin><script defer src=https://cdn.jsdelivr.net/npm/katex@0.15.2/dist/katex.min.js integrity=sha384-VQ8d8WVFw0yHhCk5E8I86oOhv48xLpnDZx5T9GogA/Y84DcCKWXDmSDfn13bzFZY crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/npm/katex@0.15.2/dist/contrib/auto-render.min.js integrity=sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR crossorigin></script>
<script>document.addEventListener("DOMContentLoaded",function(){renderMathInElement(document.body,{delimiters:[{left:"$$",right:"$$",display:!0},{left:"$",right:"$",display:!1},{left:"\\(",right:"\\)",display:!1},{left:"\\[",right:"\\]",display:!0}]})})</script><script defer src=https://cdn.jsdelivr.net/npm/mermaid@8.14.0/dist/mermaid.min.js integrity=sha384-atOyb0FxAgN9LyAc6PEf9BjgwLISyansgdH8/VXQH8p2o5vfrRgmGIJ2Sg22L0A0 crossorigin></script>
<link rel=icon type=image/png sizes=32x32 href=https://b.hui.ke/icon_hub7ca0b5404c6d576559b2bd22c64b0e5_2009_32x32_fill_box_center_3.png><link rel=apple-touch-icon sizes=180x180 href=https://b.hui.ke/icon_hub7ca0b5404c6d576559b2bd22c64b0e5_2009_180x180_fill_box_center_3.png><meta name=description content="  《汇编语言（第3版）》10.1 ~ 10.7、《零基础入门学习汇编语言》P47 ~ 49"><script type=application/ld+json>{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Docs","item":"https://b.hui.ke/docs/"},{"@type":"ListItem","position":2,"name":"汇编语言","item":"https://b.hui.ke/docs/assembly-language/"},{"@type":"ListItem","position":3,"name":"10.1 ~ 10.7","item":"https://b.hui.ke/docs/assembly-language/14/"}]}</script><script type=application/ld+json>{"@context":"https://schema.org","@type":"Article","mainEntityOfPage":{"@type":"WebPage","@id":"https://b.hui.ke/docs/assembly-language/14/"},"headline":"10.1 ~ 10.7 | 汇编语言 | Hui.Ke - Blog","datePublished":"2020-11-05T21:52:01+08:00","dateModified":"2020-11-05T21:52:01+08:00","wordCount":1400,"author":{"@type":"Person","name":"Hui.Ke"},"publisher":{"@type":"Person","name":"Hui.Ke","logo":{"@type":"ImageObject","url":"https://b.hui.ke/icon.png"}},"description":"\u003cp\u003e  《汇编语言（第3版）》10.1 ~ 10.7、《零基础入门学习汇编语言》P47 ~ 49\u003c\/p\u003e"}</script><meta property="og:title" content="10.1 ~ 10.7 | 汇编语言 | Hui.Ke - Blog"><meta property="og:type" content="article"><meta property="og:image" content="https://b.hui.ke/icon.png"><meta property="og:url" content="https://b.hui.ke/docs/assembly-language/14/"><meta property="og:description" content="  《汇编语言（第3版）》10.1 ~ 10.7、《零基础入门学习汇编语言》P47 ~ 49"><meta property="og:site_name" content="Hui.Ke - Blog"><meta property="article:published_time" content="2020-11-05T21:52:01+08:00"><meta property="article:modified_time" content="2020-11-05T21:52:01+08:00"><meta property="article:section" content="docs"><meta property="article:tag" content="call"><meta property="article:tag" content="ret"><meta property="article:tag" content="retf"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/18/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/17/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/16/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/15/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/13/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/12/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/11/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/10/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/9/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/8/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/7/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/6/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/5/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/4/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/3/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/2/"><meta property="og:see_also" content="https://b.hui.ke/docs/assembly-language/1/"><script>!function(e){"use strict";!function(){var i,s=window,o=document,a=e,c="".concat("https:"===o.location.protocol?"https://":"http://","sdk.51.la/js-sdk-pro.min.js"),n=o.createElement("script"),r=o.getElementsByTagName("script")[0];n.type="text/javascript",n.setAttribute("charset","UTF-8"),n.async=!0,n.src=c,n.id="LA_COLLECT",a.d=n,i=function(){s.LA.ids.push(a)},s.LA?s.LA.ids&&i():(s.LA=e,s.LA.ids=[],i()),r.parentNode.insertBefore(n,r)}()}({id:"Jgb8aUbG5e3rqhrs",ck:"Jgb8aUbG5e3rqhrs",autoTrack:!0,hashMode:!0})</script><body class="flex min-h-screen flex-col"><header class="min-h-16 pl-scrollbar bg-secondary-bg fixed z-50 flex w-full items-center shadow-sm"><div class="mx-auto w-full max-w-screen-xl"><script>let storageColorScheme=localStorage.getItem("lightDarkMode");((storageColorScheme=="Auto"||storageColorScheme==null)&&window.matchMedia("(prefers-color-scheme: dark)").matches||storageColorScheme=="Dark")&&document.getElementsByTagName("html")[0].classList.add("dark")</script><nav class="flex items-center justify-between flex-wrap px-4 py-4 md:py-0"><a href=/ class="me-6 text-primary-text text-xl font-bold">Hui.Ke - Blog</a>
<button id=navbar-btn class="md:hidden flex items-center px-3 py-2" aria-label="Open Navbar">
<i class="fas fa-bars"></i></button><div id=target class="hidden block md:flex md:grow md:justify-between md:items-center w-full md:w-auto text-primary-text z-20"><div class="md:flex md:h-16 text-sm md:grow pb-4 md:pb-0 border-b md:border-b-0"><a href=/posts/ class="block mt-4 md:inline-block md:mt-0 md:h-(16-4px) md:leading-(16-4px) box-border md:border-t-2 md:border-b-2 border-transparent me-4">Posts</a>
<a href=/docs/ class="block mt-4 md:inline-block md:mt-0 md:h-(16-4px) md:leading-(16-4px) box-border md:border-t-2 md:border-b-2 selected-menu-item me-4">Docs</a>
<a href=/categories/ class="block mt-4 md:inline-block md:mt-0 md:h-(16-4px) md:leading-(16-4px) box-border md:border-t-2 md:border-b-2 border-transparent me-4">Categories</a>
<a href=/series/ class="block mt-4 md:inline-block md:mt-0 md:h-(16-4px) md:leading-(16-4px) box-border md:border-t-2 md:border-b-2 border-transparent me-4">Series</a>
<a href=/tags/ class="block mt-4 md:inline-block md:mt-0 md:h-(16-4px) md:leading-(16-4px) box-border md:border-t-2 md:border-b-2 border-transparent me-4">Tags</a>
<a href=/love/ class="block mt-4 md:inline-block md:mt-0 md:h-(16-4px) md:leading-(16-4px) box-border md:border-t-2 md:border-b-2 border-transparent me-4">Love</a>
<a href=/about/ class="block mt-4 md:inline-block md:mt-0 md:h-(16-4px) md:leading-(16-4px) box-border md:border-t-2 md:border-b-2 border-transparent me-4">About</a></div><div class=flex><div class="relative pt-4 md:pt-0"><div class="cursor-pointer hover:text-eureka" id=lightDarkMode><i class="fas fa-adjust"></i></div><div class="fixed hidden inset-0 opacity-0 h-full w-full cursor-default z-30" id=is-open></div><div class="absolute flex flex-col start-0 md:start-auto end-auto md:end-0 hidden bg-secondary-bg w-48 rounded py-2 border border-tertiary-bg cursor-pointer z-40" id=lightDarkOptions><span class="px-4 py-1 hover:text-eureka" name=Light>Light</span>
<span class="px-4 py-1 hover:text-eureka" name=Dark>Dark</span>
<span class="px-4 py-1 hover:text-eureka" name=Auto>Auto</span></div></div></div></div><div class="fixed hidden inset-0 opacity-0 h-full w-full cursor-default z-0" id=is-open-mobile></div></nav><script>let element=document.getElementById("lightDarkMode");storageColorScheme==null||storageColorScheme=="Auto"?document.addEventListener("DOMContentLoaded",()=>{window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",switchDarkMode)}):storageColorScheme=="Light"?(element.firstElementChild.classList.remove("fa-adjust"),element.firstElementChild.setAttribute("data-icon","sun"),element.firstElementChild.classList.add("fa-sun")):storageColorScheme=="Dark"&&(element.firstElementChild.classList.remove("fa-adjust"),element.firstElementChild.setAttribute("data-icon","moon"),element.firstElementChild.classList.add("fa-moon")),document.addEventListener("DOMContentLoaded",()=>{getcolorscheme(),switchBurger()})</script></div></header><main class="grow pt-16"><div class=pl-scrollbar><div class="mx-auto w-full max-w-screen-xl lg:px-4 xl:px-8"><div class=lg:pt-12><div class="flex flex-col md:flex-row bg-secondary-bg rounded"><div class="md:w-1/4 lg:w-1/5 border-e"><div class="sticky top-16 pt-6"><div id=sidebar-title class="md:hidden mx-4 px-2 pt-4 pb-2 md:border-b text-tertiary-text md:text-primary-text"><span class=font-semibold>Table of Contents</span>
<i class='fas fa-caret-right ms-1'></i></div><div id=sidebar-toc class="hidden md:block overflow-y-auto mx-6 md:mx-0 pe-6 pt-2 md:max-h-doc-sidebar bg-primary-bg md:bg-transparent"><div class="flex flex-wrap ms-4 -me-2 p-2 bg-secondary-bg md:bg-primary-bg rounded"><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/>汇编语言</a></div><ul class=ps-6><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/18/>11.9 ~ 11.11</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/17/>11.7 ~ 11.9</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/16/>11.1 ~ 11.6</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/15/>10.8 ~ 10.12</a></div></li><li class=py-2><div><a class="text-eureka hover:text-eureka" href=https://b.hui.ke/docs/assembly-language/14/>10.1 ~ 10.7</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/13/>9.7 ~ 9.9</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/12/>9.1 ~ 9.6</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/11/>8.5 ~ 8.9</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/10/>8.1</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/9/>7.1 ~ 7.10</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/8/>6.1 ~ 6.3</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/7/>5.1 ~ 5.4</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/6/>4.1 ~ 4.9</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/5/>3.6 ~ 3.10</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/4/>3.1 ~ 3.5</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/3/>2.8 ~ 2.12</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/2/>1.11 ~ 2.6</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/assembly-language/1/>1.1 ~ 1.10</a></div></li></ul></div></div></div><div class="w-full md:w-3/4 lg:w-4/5 pb-8 pt-2 md:pt-8"><div class=flex><div class="w-full lg:w-3/4 px-6"><article class=prose><h1 class=mb-4>10.1 ~ 10.7</h1><div class="text-tertiary-text not-prose mt-2 flex flex-row flex-wrap items-center"><div class="me-6 my-2"><i class="fas fa-calendar me-1"></i>
<span>2020-11-05</span></div><div class="me-6 my-2"><i class="fa-solid fa-pen-to-square me-1"></i>
<span>2020-11-05</span></div><div class="me-6 my-2"><i class="fas fa-clock me-1"></i>
<span>3 min read</span></div><div class="me-6 my-2"><i class="fas fa-folder me-1"></i>
<a href=https://b.hui.ke/categories/it/ class=hover:text-eureka>IT</a></div><div class="me-6 my-2"><i class="fas fa-th-list me-1"></i>
<a href=https://b.hui.ke/series/x86asm-language/ class=hover:text-eureka>x86asm Language</a></div><div class="me-6 my-2"><i class="fa-solid fa-eye me-1"></i>
<span id=busuanzi_value_page_pv><i class="fa fa-spinner fa-spin"></i></span> Hits</div></div><p>  《汇编语言（第3版）》10.1 ~ 10.7、《零基础入门学习汇编语言》P47 ~ 49</p><h2 id=第十章-call-和-ret-指令>第十章 Call 和 Ret 指令</h2><p>  call 和 ret 指令都是转移指令，它们都修改 IP，或同时修改 CS 和 IP。</p><p>  它们经常被共同用来实现程序的设计。</p><h3 id=101-ret-和-retf>10.1 ret 和 retf</h3><p>  ret 指令用栈中的数据，修改 IP 的内容，从而实现近转移。</p><p>  CPU 执行 ret 指令时，进行下面的两步操作</p><ol><li>(IP)=((ss)*16+(sp))</li><li>(sp)=(sp)+2</li></ol><p>  retf 指令用栈中的数据，修改 CS 和 IP 的内容，从而实现远转移；</p><p>  CPU 执行 retf 指令时，进行下面几步操作</p><ol><li>(IP)=((ss)*16+(sp))</li><li>(sp)=(sp)+2</li><li>(cs)=((ss)*16+(sp))</li><li>(sp)=(sp)+2</li></ol><p>  可以看出，如果我们用汇编语法来解释 ret 和 retf 指令，则</p><ol><li><p>CPU 执行 ret 指令时，相当于进行</p><pre><code class=language-x86asm>pop IP
</code></pre></li><li><p>CPU 执行 retf 指令时，相当于进行</p><pre><code class=language-x86asm>pop IP
pop CS
</code></pre></li></ol><h3 id=102-call-指令>10.2 call 指令</h3><p>  call 指令经常跟 ret 指令配合使用，因此 CPU 执行 call 指令，进行两步操作</p><ol><li>将当前的 IP 或 CS 和 IP 压入栈中；</li><li>转移（jmp）。</li></ol><blockquote><p>call 指令<strong>不能实现</strong><del>短转移</del>，除此之外，call 指令实现转移的方法和 jmp 指令的原理相同。</p></blockquote><h3 id=103-依据位移进行转移的-call-指令>10.3 依据位移进行转移的 call 指令</h3><p>  call 标号（将当前的 IP 压栈后，转到标号处执行指令）</p><p>  CPU 执行此种格式的 call 指令时，进行如下的操作</p><ol><li>(sp)=(sp)-2</li><li>((ss)*16+(sp))=(IP)</li><li>(IP)=(IP)+16 位位移</li></ol><p>  16 位位移 =“标号”处的地址 -call 指令后的第一个字节的地址；</p><p>  16 位位移的范围为 -32768~32767，用补码表示；</p><p>  16 位位移由编译程序在编译时算出。</p><p>  从上面的描述中，可以看出，如果用汇编语法来解释此种格式的 call 指令。则</p><p>  CPU 执行指令“call 标号”时，相当于进行</p><pre><code class=language-x86asm>push IP
jmp near ptr 标号
</code></pre><h3 id=104-转移的目的地址在指令中的-call-指令>10.4 转移的目的地址在指令中的 call 指令</h3><p>  call 指令，其对应的机器指令中并没有转移的目的地址，而是相对于当前 IP 的转移位移。</p><p>  指令“call far ptr 标号”实现的是段间转移。</p><p>  CPU 执行“call far ptr 标号”这种格式的 call 指令时的操作</p><ol><li>(sp)=(sp)-2</li><li>((ss)×16+(sp))=(CS)</li><li>(sp)=(sp)-2</li><li>((ss)×16+(sp))=(IP)</li><li>(CS)= 标号所在的段地址</li><li>(IP)= 标号所在的偏移地址</li></ol><p>  从上面的描述中可以看出，如果我们用汇编语法来解释此种格式的 call 指令，则</p><p>  CPU 执行指令“call far ptr 标号”时，相当于进行</p><pre><code class=language-x86asm>push CS
push IP
jmp far ptr 标号
</code></pre><h3 id=105-转移地址在寄存器中的-call-指令>10.5 转移地址在寄存器中的 call 指令</h3><p>  指令格式：call 16 位寄存器</p><p>  功能</p><ol><li>(sp)=(sp)-2</li><li>((ss)×16+(sp))=(IP)</li><li>(IP)=(16 位寄存器)</li></ol><p>  汇编语法解释此种格式的 call 指令，CPU 执行 call 16 位 reg 时，相当于进行</p><pre><code class=language-x86asm>push IP
jmp 16 位寄存器
</code></pre><h3 id=106-转移地址在内存中的-call-指令>10.6 转移地址在内存中的 call 指令</h3><p>  转移地址在内存中的 call 指令有两种格式</p><ol><li><p>call word ptr 内存单元地址</p><ol><li><p>汇编语法解释</p><pre><code class=language-x86asm>push IP
jmp word ptr 内存单元地址
</code></pre></li><li><p>示例</p><pre><code class=language-x86asm>mov sp,10h
mov ax,0123h
mov ds:[0],ax
call word ptr ds:[0]     # 执行后，(IP)=0123H，(sp)=0EH
</code></pre></li></ol></li><li><p>call dword ptr 内存单元地址</p><ol><li><p>汇编语法解释</p><pre><code class=language-x86asm>push CS
push IP
jmp dword ptr 内存单元地址
</code></pre></li><li><p>示例</p><pre><code class=language-x86asm>mov sp,10h
mov ax,0123h
mov ds:[0],ax
call word ptr ds:[2],0
call dword ptr ds:[0]     # 执行后，(CS)=0，(IP)=0123H，(sp)=0CH
</code></pre></li></ol></li></ol><h3 id=107-call-和-ret-的配合使用>10.7 call 和 ret 的配合使用</h3><p>  前面，我们已经分别学习了 ret 和 call 指令的原理。现在我们看一下，如何将它们配合使用来实现子程序的机制。</p><h3 id=问题-101>问题 10.1</h3><p>  下面程序返回前，bx 中的值是多少？</p><pre><code class=language-x86asm>assume cs:code
code segment
start:
	mov ax,1
	mov ax,3
	call s
	mov bx,ax
	mov ax,4c00h
	int 21h
	s:
		add ax,ax
		loop s
	ret
code ends
end start
</code></pre><p>  我们来看一下 CPU 执行这个程序的主要过程</p><ol><li>CPU 将 call s 指令的机器码读入，IP 指向了 call s 后的指令 mov bx,ax，然后 CPU 执行 call s 指令，将当前的 IP 值（指令 mov bx,ax 的偏移地址）压栈，并将 IP 的值改变为标号 s 处的偏移地址；</li><li>CPU 从标号 s 处开始执行指令，loop 循环完毕，(ax)=8；</li><li>CPU 将 ret 指令的机器码读入，IP 指向了 ret 指令后的内存单元，然后 CPU 执行 ret 指令，从栈中弹出一个值（即 call 先前压入的 mov bx,ax 指令的偏移地址）送入 IP 中。则 CS:IP 指向指令 mov bx,ax；</li><li>CPU 从 mov bx,ax 开始执行指令，直至完成。</li></ol><p>  因此，程序返回前，(bx)=8。我们可以看出，从标号 s 到 ret 的程序段的作用是计算 2 的 N 次方，计算前，N 的值由 CX 提供。</p></article><div class=my-4><a href=https://b.hui.ke/tags/call/ class="inline-block bg-tertiary-bg text-sm rounded px-3 py-1 my-1 me-2 hover:text-eureka">#call</a>
<a href=https://b.hui.ke/tags/ret/ class="inline-block bg-tertiary-bg text-sm rounded px-3 py-1 my-1 me-2 hover:text-eureka">#ret</a>
<a href=https://b.hui.ke/tags/retf/ class="inline-block bg-tertiary-bg text-sm rounded px-3 py-1 my-1 me-2 hover:text-eureka">#retf</a></div><div class=py-2><div class="my-8 flex flex-col items-center md:flex-row"><a href=https://b.hui.ke/authors/hui.ke/ class="md:me-4 text-primary-text h-24 w-24"><img src=https://b.hui.ke/bagua.webp class="bg-primary-bg w-full rounded-full" alt=Avatar></a><div class="mt-4 w-full md:mt-0 md:w-auto"><a href=https://b.hui.ke/authors/hui.ke/ class="mb-2 block border-b pb-1 text-lg font-bold"><h3>Hui.Ke</h3></a><span class="block pb-2">❤ Cyber Security | Safety is a priority.</span>
<a href=mailto:3199731997@qq.com class=me-2><i class="fas fa-envelope"></i></a>
<a href="https://wpa.qq.com/msgrd?v=3&uin=3199731997" class=me-2><i class="fab fa-qq"></i></a>
<a href=/images/aixinxianquan.webp class=me-2><i class="fab fa-weixin"></i></a></div></div></div><div class="-mx-2 mt-4 flex flex-col border-t px-2 pt-4 md:flex-row md:justify-between"><div><span class="text-primary-text block font-bold">Previous</span>
<a href=https://b.hui.ke/docs/assembly-language/15/ class=block>10.8 ~ 10.12</a></div><div class="mt-4 md:mt-0 md:text-right"><span class="text-primary-text block font-bold">Next</span>
<a href=https://b.hui.ke/docs/assembly-language/13/ class=block>9.7 ~ 9.9</a></div></div><div id=valine-comments class=mt-4></div><script defer src=https://cdn.jsdelivr.net/npm/valine@1.4.16/dist/Valine.min.js integrity=sha384-e0+DNUCJo75aOAzHQbFWYBCM9/S4f0BhRJXvEgbE3mMS85RM20MSSGStHuNdY2QK crossorigin></script>
<script>document.addEventListener("DOMContentLoaded",function(){new Valine({el:"#valine-comments",appId:"BQnVqWIiq78AdqwyhvBVAa3y-MdYXbMMI",appKey:"RKg5By312YjM8rU6WkkfK9IN",recordIP:"true",serverURLs:"https://l.hui.ke",visitor:"true"})})</script></div><div class="hidden lg:block lg:w-1/4"><div class="bg-secondary-bg
prose sticky top-16 z-10 hidden px-6 py-4 lg:block"><h3>On This Page</h3></div><div class="sticky-toc
border-s
hidden px-6 pb-6 lg:block"><nav id=TableOfContents><ul><li><a href=#第十章-call-和-ret-指令>第十章 Call 和 Ret 指令</a><ul><li><a href=#101-ret-和-retf>10.1 ret 和 retf</a></li><li><a href=#102-call-指令>10.2 call 指令</a></li><li><a href=#103-依据位移进行转移的-call-指令>10.3 依据位移进行转移的 call 指令</a></li><li><a href=#104-转移的目的地址在指令中的-call-指令>10.4 转移的目的地址在指令中的 call 指令</a></li><li><a href=#105-转移地址在寄存器中的-call-指令>10.5 转移地址在寄存器中的 call 指令</a></li><li><a href=#106-转移地址在内存中的-call-指令>10.6 转移地址在内存中的 call 指令</a></li><li><a href=#107-call-和-ret-的配合使用>10.7 call 和 ret 的配合使用</a></li><li><a href=#问题-101>问题 10.1</a></li></ul></li></ul></nav></div><script>window.addEventListener("DOMContentLoaded",()=>{enableStickyToc()})</script></div></div></div></div></div><script>document.addEventListener("DOMContentLoaded",()=>{hljs.highlightAll(),changeSidebarHeight(),switchDocToc()})</script></div></div></main><footer class=pl-scrollbar><div class="mx-auto w-full max-w-screen-xl"><div class="text-center p-6 pin-b"><script async src=/js/click.js></script><div id=poem_ip></div><script type=text/javascript>jinrishici.load(function(e){tags.innerHTML=e.data.matchTags})</script><div><span id=timeDate>载入年天数...</span><span id=times>载入时分秒...</span>
<script async src=/js/duration.js></script></div><a href=https://www.foreverblog.cn/go.html target=_blank><img src=https://img.foreverblog.cn/wormhole_4_tp.gif alt style=display:inline-block;width:auto;height:32px title=穿梭虫洞-随机访问十年之约友链博客></a><p class="text-sm text-tertiary-text"><script async src=//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js></script>本站总访问量 <span id=busuanzi_value_site_pv></span> 次
&#183; 您是本站的第 <span id=busuanzi_value_site_uv></span> 个小伙伴</p><script async src=/js/tab.js></script></div></div></footer></body></html>